const path = require('path');

const config = {
  projectName: 'myapp',
  date: '2024-3-31',
  designWidth: 375,
  deviceRatio: {
    640: 2.34 / 2,
    750: 1,
    828: 1.81 / 2,
    375: 2 / 1
  },
  onePxTransform: true,
  sourceRoot: 'src',
  outputRoot: 'dist',
  alias: {
    src: path.resolve(__dirname, '..', 'src'),
    assets: path.resolve(__dirname, '..', 'src/assets'),
    components: path.resolve(__dirname, '..', 'src/components'),
    pages: path.resolve(__dirname, '..', 'src/pages'),
    store: path.resolve(__dirname, '..', 'src/store'),
    utils: path.resolve(__dirname, '..', 'src/utils'),
    hooks: path.resolve(__dirname, '..', 'src/hooks')
  },
  cache: {
    enable: true
  },
  plugins: [[
    '@tarojs/plugin-html',
    {
      modifyElements(inline: string[], block: string[]) {
        // 行内元素增加 <xxx>
        // inline.push('xxx')
        // 行内元素添加 <span>，块级元素删除 <span>
        inline.push('span')
        block.splice(block.indexOf('span'), 1)

        block.push('code')
        inline.splice(inline.indexOf('code'), 1)
      },
    }
  ]],
  defineConstants: {
  },
  copy: {
    patterns: [
      {
        from: 'src/wemark',
        to: 'dist/wemark',
      }
    ],
    options: {
    }
  },
  framework: 'react',
  compiler: {
    type: 'webpack5',
    prebundle: { enable: false }
  },
  mini: {
    miniCssExtractPluginOption: {
      ignoreOrder: true,
    },
    postcss: {
      pxtransform: {
        enable: true,
        config: {
          selectorBlackList: ['nut-']
        }
      },
      url: {
        enable: true,
        config: {
          limit: 1024 // 设定转换尺寸上限
        }
      },
      cssModules: {
        enable: true, // 默认为 false，如需使用 css modules 功能，则设为 true
        config: {
          namingPattern: 'module', // 转换模式，取值为 global/module
          generateScopedName: '[name]__[local]___[hash:base64:5]'
        }
      }
    },
    performance: {
      hints: false,
      maxEntrypointSize: 512000,
      maxAssetSize: 512000
    },
    webpackChain(chain, webpack) {
      chain.merge({
        module: {
          rule: {
            myloader: {
              test: /\.md$/,
              use: [
                {
                  loader: 'raw-loader',
                  options: {},
                },
              ],
            },
          },
        },
      })
    },
  },
  h5: {
    publicPath: '/',
    staticDirectory: 'static',
    // esnextModules: ['nutui-react'],
    postcss: {
      pxtransform: {
        enable: false,
        config: {
          selectorBlackList: ['nut-']
        }
      },
      autoprefixer: {
        enable: true,
        config: {
        }
      },
      cssModules: {
        enable: false, // 默认为 false，如需使用 css modules 功能，则设为 true
        config: {
          namingPattern: 'module', // 转换模式，取值为 global/module
          generateScopedName: '[name]__[local]___[hash:base64:5]'
        }
      }
    }
  }
}

module.exports = function (merge) {
  if (process.env.NODE_ENV === 'development') {
    return merge({}, config, require('./dev'))
  }
  return merge({}, config, require('./prod'))
}
